package cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content;

import cn.iocoder.yudao.framework.apilog.core.annotations.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.Level_ContentPageReqVO;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.Level_ContentRespVO;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.Level_ContentSaveReqVO;
import cn.iocoder.yudao.module.yyzx.controller.admin.outgoing.vo.OutgoingPageReqVO;
import cn.iocoder.yudao.module.yyzx.controller.admin.outgoing.vo.OutgoingRespVO;
import cn.iocoder.yudao.module.yyzx.service.nurse_level_content.Level_ContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 床位信息")
@RestController
@RequestMapping("/yyzx/level_content")
@Validated
public class Level_ContentController {

    @Resource
    private Level_ContentService level_contentService;

    @PostMapping("/create")
    @Operation(summary = "创建床位信息")
    @PreAuthorize("@ss.hasPermission('yyzx:level_content:create')")
    public CommonResult<Integer> createBed(@Valid @RequestBody Level_ContentSaveReqVO createReqVO) {
        return success(level_contentService.createLevel_Content(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新床位信息")
    @PreAuthorize("@ss.hasPermission('yyzx:level_content:update')")
    public CommonResult<Boolean> updateBed(@Valid @RequestBody Level_ContentSaveReqVO updateReqVO) {
        level_contentService.updateLevel_Content(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除床位信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('yyzx:level_content:delete')")
    public CommonResult<Boolean> deleteBed(@RequestParam("id") Integer id) {
        level_contentService.deleteLevel_Content(id);
        return success(true);
    }

//    @GetMapping("/get")
//    @Operation(summary = "获得床位信息")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('yyzx:level_content:query')")
//    public CommonResult<Level_ContentRespVO> getBed(@RequestParam("id") Integer id) {
//        Level_ContentRespVO level_content = check_outService.getLevel_Content(id);
//        return success(BeanUtils.toBean(level_content, Level_ContentRespVO.class));
//    }

    @GetMapping("/page")
    @Operation(summary = "获得床位信息分页")
    @PreAuthorize("@ss.hasPermission('yyzx:level_content:query')")
    public CommonResult<PageResult<Level_ContentPageReqVO>> getBedPage(@Valid Level_ContentPageReqVO pageReqVO) {
<<<<<<< HEAD
        System.out.println("pageReqVO.getId() = " + pageReqVO.getId());
        PageResult<Level_ContentPageReqVO> contentByLevelId = level_contentService.getContentByLevelId(pageReqVO.getId());
        System.out.println("contentByLevelId = " + contentByLevelId);
        return null;
//        return success(BeanUtils.toBean(contentByLevelId, Level_ContentPageReqVO.class));
//        PageResult<Level_ContentPageReqVO> pageResult = check_outService.getLevel_ContentPage(levelId);
//        System.out.println("pageResult = " + pageResult);
//        return success(BeanUtils.toBean(pageResult, Level_ContentPageReqVO.class));
=======
        System.out.println("pageReqVO ====================== " + pageReqVO);
        PageResult<Level_ContentPageReqVO> pageResult = check_outService.getLevel_ContentPage(pageReqVO);
        System.out.println("pageResult = " + pageResult);
        return success(BeanUtils.toBean(pageResult, Level_ContentPageReqVO.class));
>>>>>>> c60a0b97bb763415089ed7dee2a013349c477068
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出床位信息 Excel")
    @PreAuthorize("@ss.hasPermission('yyzx:level_content:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBedExcel(@Valid Level_ContentPageReqVO pageReqVO, HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<? extends Level_ContentPageReqVO> list = level_contentService.getLevel_ContentPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "床位信息.xls", "数据", Level_ContentRespVO.class,
                BeanUtils.toBean(list, Level_ContentRespVO.class));
    }

}